import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

public class FileInAndOut {
	public static String fileInput(String fName) {
		StringBuffer strRead =new StringBuffer();
		try {
			FileInputStream fis=new FileInputStream(fName);
			InputStreamReader isr=new InputStreamReader(fis,"gbk");			
			BufferedReader br = new BufferedReader(isr);
			String aline = new String();
			while ((aline = br.readLine()) != null)
				strRead.append(aline);
			br.close();
			isr.close();
			fis.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return strRead.toString();
	}

	public static void fileWrite(String fName, String temp) {
		try {
			FileOutputStream fos=new FileOutputStream(fName);
			OutputStreamWriter osw=new OutputStreamWriter(fos, "gbk");
			BufferedWriter bw = new BufferedWriter(osw);
			bw.write(temp);
			bw.close();
			osw.close();
			fos.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
